$(function(){
	var search_btn = $(".search_btn"),
		search = $(".search"),
		content = $(".content"),
		footer = $(".footer"),
		closeBtn = $(".s_close"),
		menu_btn = $(".menu_btn"),
		menu_per = $(".menu_per"),
		content = $(".content"),
		footer = $(".footer"),
		ljdl = $(".ljdl"),
		login = $(".login"),
		drop_down = $(".sort_pro .drop_down"),
		l_span = $(".l_span"),
		profile = $(".profile"),
		denglu = $(".denglu");
	exit_pro = $(".exit_pro"),
		gimc = $(".gimc");
	
	search_btn.on("click", function(e) { //当点击头部导航栏右上角搜索按钮的时候,
		search.addClass("active"); //给search这个类添加一个"active"(在css样式里定义active)的类，
		content.css("display", "none"); //同时将首页内容
		footer.css("display", "none"); //和底部内容隐藏
	})
	closeBtn.on("click", function(e) { //当点击头部搜索栏左上角关闭按钮的时候,
		search.removeClass("active"); //将search里已添加"active"的类移除，
		content.css("display", "block"); //同时将首页内容
		footer.css("display", "block"); //和底部内容显示出来
		menu_per.removeClass("left_on"); //给menu_per里的left_on移除(将登录页面往左隐藏)
		profile.css("display", "none");
		drop_down.removeClass("block");
		l_span.removeClass("down");
		menu_per.css("padding-bottom", "0px");
		profile.css("padding-bottom", "0px");
	})
	menu_btn.on("click", function(e) { //当点击头部导航栏左上角菜单按钮的时候,
		menu_per.addClass("left_on"); //给menu_per添加一个left_on的类(将位于主页内容左边的登录页面往右显示出来)
		content.fadeOut(); //同时将首页内容
		footer.fadeOut(); //和底部内容隐藏
	})
	ljdl.on("click", function(e) { //当在登录页面点击"立即登录"时，
		menu_per.addClass("none");
		login.css("display", "block");
		drop_down.removeClass("block");
		l_span.removeClass("down");
		menu_per.css("padding-bottom", "0px");
		profile.css("padding-bottom", "0px");
	})
	denglu.on("click", function(e) {
		login.css("display", "none");
		profile.css("display", "block");
	})
	
	exit_pro.on("click", function(e) {
		profile.css("display", "none");
		menu_per.addClass("block");
		drop_down.removeClass("block");
		l_span.removeClass("down");
		menu_per.css("padding-bottom", "0px");
		profile.css("padding-bottom", "0px");
	})
	
	gimc.on("click", function(e) {
		if (drop_down.attr("class") == "drop_down") {
			drop_down.addClass("block");
			l_span.addClass("down");
			menu_per.css("padding-bottom", "30px");
			profile.css("padding-bottom", "80px");
		} else {
			drop_down.removeClass("block");
			l_span.removeClass("down");
			menu_per.css("padding-bottom", "0px");
			profile.css("padding-bottom", "0px");
		};
	})
	
	//轮播图
	var window_width=$(document).width();
// 		html.css("font-size",window_width/40+"px")
		$(window).on("resize",function(e){
			window_width = $(document).width();
			hehe(window_width);
//			 html.css("font-size",window_width/40+"px")
			
		})
	var banner=$(".banner");
    var ul=$(".banner ul");
    var first_li = $(".banner ul li:first-of-type").clone();
    $(".banner ul li:last-of-type").after(first_li);
    var lis=ul.find("li");
    var lis_len=lis.length;
    var maxlen=lis_len*window_width;
    var left=parseInt(ul.css("left"));
    var lih;
    ul.css("width",maxlen+"px");
	lis.css("width",window_width+"px");
	var imgh=ul.css("height");
	lih=parseInt(imgh);
	banner.css("height",0.556*window_width+"px");
	function hehe(x){
		maxlen=lis_len*x;
		ul.css("width",maxlen+"px");
		lis.css("width",x+"px");
		banner.css("height",0.556*x+"px");
		ul.css("left",-i*window_width);
	}
	var window_w;
	var i = 0;
		function moveR(window_width){
			i++;
			if(i==lis_len){
				ul.css("left",0+"px");
				i=1;
			}
			ul.stop().animate({left:-i*window_width},300);
		};
		function moveL(){
			i--;
			if(i==-1){
				ul.css("left",-(lis_len-1)*window_width);
				i = lis_len-2;
			}
			ul.stop().animate({left:-i*window_width},300);
		};
		var t = setInterval(function(){
			moveR(window_width);
		},3000
			
		)
    var startX; //触摸起始横坐标  
    var startY; //触摸起始纵坐标  
    var moveSpave; //移动的距离  
    var isMoveX = true; //判断是否为左右移动  
    var isFirst = true;   //是否要判断touchmove方向  
    lis.on("touchstart touchmove touchend touchcancel", function (e) {  
        e.preventDefault(); //该区域禁止滑动切换页面  
        if (e.originalEvent.type == "touchstart") {  
            startX = e.originalEvent.touches[0].pageX; //触摸起始位置赋值  
            startY = e.originalEvent.touches[0].pageY; //触摸起始位置赋值  
            isFirst = true; 
            clearInterval(t);
        }  
        else if (e.originalEvent.type == "touchmove") {  
        var moveX = e.originalEvent.touches[0].pageX  
        var moveY = e.originalEvent.touches[0].pageY;  
            if (isFirst){  
                Math.abs(moveX - startX) - Math.abs(moveY - startY) >= 2 ? isMoveX = true : isMoveX = false;  
                isFirst = false;  
                return;  
            }   
            if (isMoveX){  
            //水平滑动  
                moveSpave = moveX - startX;  
            }else{  
	            //竖直滑动  
	            moveSpave = moveY - startY;  
	        	}   
			}else if(e.originalEvent.type == "touchend"){  
                if (isMoveX) {  
                if (moveSpave < 0 ) {  
                //向左滑动  
					moveR(window_width);
            }  
            else if (moveSpave > 0 ) {  
            //向右滑动  
			moveL();
            }  
            }
            t = setInterval(function(){
				moveR(window_width);
			},3000		
			)}
            });  
})
